import numpy as np
from scipy.interpolate import CubicSpline
import matplotlib.pyplot as plt
# 输入数据点
x = np.array([1, 2, 3, 4, 5])
y = np.array([5, 2, 1, 4, 3])

# 目标插值点
x_interp = np.linspace(1, 5, 100)
# 执行三次样条插值
cs = CubicSpline(x, y)
y_interp = cs(x_interp)


# 绘制原始数据点
plt.scatter(x, y, color='red', label='Original Data')

# 绘制插值结果
plt.plot(x_interp, y_interp, label='Cubic Spline')
plt.legend()
plt.show()